package com.hnust.dao;

import com.hnust.domain.AuditJoin;
import com.hnust.domain.record.AuditJoinRecord;
import com.hnust.domain.record.AuditRegisterRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 创建人：gh
 * 创建时间：2020/10/6
 * 描述：审核加入、审核注册
 */

@Mapper
@Repository
public interface AuditDao {

    @Select("select * from audit_join where aud_join_id=#{id}")
    @ResultType(AuditJoin.class)
    AuditJoin getAuditJoin(String id);

    //点击审核加入时，返回审核信息
    @Select("select audit_join.aud_join_id as auditJoinId, \n" +
            "audit_join.result, audit_join.tea_id as teacherId, \n" +
            "teacher.name as teacherName, \n" +
            "teacher.tea_number as teacherAccount,\n" +
            "audit_join.cou_gro_id as courseGroupId,\n" +
            "course_group.open_time as courseGroupTime,\n" +
            "course.name as course\n" +
            "from audit_join, teacher, course_group, course\n" +
            "where audit_join.tea_id = teacher.tea_id and audit_join.cou_gro_id = course_group.cou_gro_id and course_group.cou_id = course.cou_id and course_group.col_id = #{collegeId}\n" +
//            "limit #{rows} offset #{current}")
    "")
    @ResultType(AuditJoinRecord.class)
    List<AuditJoinRecord> auditJoinGet(String collegeId, Integer rows, Integer current);

    //通过或者驳回审核加入
    @Update("update audit_join set result = #{result} where aud_join_id = #{auditJoinId}")
    @ResultType(Integer.class)
    int auditJoinOperate(String auditJoinId, Integer result);

    // 点击审核注册时，返回审核信息
    @Select("select \n" +
            "audit_register.aud_reg_id as auditRegisterId,\n" +
            "audit_register.tea_id as teacherId,\n" +
            "teacher.name as teacherName,\n" +
            "teacher.tea_number as teaNumber,\n" +
            "audit_register.result\n" +
            "from audit_register, teacher\n" +
            "where audit_register.tea_id = teacher.tea_id and teacher.col_id = #{collegeId}\n" +
            "limit #{rows} offset #{current}")
    @ResultType(AuditRegisterRecord.class)
    List<AuditRegisterRecord> auditRegisterGet(String collegeId, Integer rows, Integer current);

    // 通过注册/驳回注册
    @Update("update audit_register set result = #{result} where aud_reg_id = #{auditRegisterId}")
    @ResultType(Integer.class)
    int auditRegisterOperate(String auditRegisterId, Integer result);

}
